// programma hod konem!

import java.util.Scanner;
public class knight
{
	static int lenght = 5;
	static int arr[][];
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		System.out.print("Input the size of the board: ");
		lenght = cin.nextInt();
		arr = new int[lenght][lenght];

		System.out.print("Input start coordinate for x: ");
		int x = cin.nextInt();

		System.out.print("Input start coordinate for y: ");
		int y = cin.nextInt();
		
		int sum = 0;
		for(int i = 0; i < arr.length; i++)
			for(int j = 0; j < arr[0].length; j++)
				sum += knight(i, j);

		System.out.println("Number of options (" + x + ";" + y + "): " + knight(x, y));
	}

	private static void printArr(int arr[][])
	{
		System.out.println();
		for(int i = 0; i < arr.length; i++)
		{
			for(int j = 0; j < arr[0].length; j++)
				System.out.print(arr[i][j] + "   ");
			System.out.println();
		}
	}

	private static int knight(int x, int y)
	{
		return knight(x, y, 1);
	}
	private static int knight(int x, int y, int level)
	{
		if(x >= 0 && x <= lenght-1)
			if(y >= 0 && y <= lenght-1)
				if(arr[x][y] == 0)
				{
					arr[x][y] = level;
					if(level == lenght*lenght)
					{
						printArr(arr);
						arr[x][y] = 0;
						return 1;
					}
					else
					{
						int sum = 0;
						sum += knight(x-2, y-1, level+1);
						sum += knight(x-1, y-2, level+1);
						sum += knight(x+1, y-2, level+1);
						sum += knight(x+2, y-1, level+1);
						sum += knight(x+2, y+1, level+1);
						sum += knight(x+1, y+2, level+1);
						sum += knight(x-1, y+2, level+1);
						sum += knight(x-2, y+1, level+1);
						arr[x][y] = 0;
						return sum;
					}
				}
		return 0;
	}
}